package com.xywy.tangandroid.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.xywy.tangandroid.R;
import com.xywy.tangandroid.base.BasicAdapter;
import com.xywy.tangandroid.receiver.BroadcastAction;
import com.xywy.tangandroid.util.Constant;
import com.xywy.tangandroid.util.LogUtil;

public class ProfessionAdapter extends BasicAdapter<String> {
	private LayoutInflater inflater;
	
	private SetProfession profession;
	
	public ProfessionAdapter(Context context, List<String> list) {
		super(context, list);
		this.inflater = LayoutInflater.from(context);
		
	}
   @Override
public View getView(int position, View convertView, ViewGroup parent) {
	   final int i=position;
	   viewholder  holder=new viewholder();
	   convertView = inflater.inflate(R.layout.item_popwindow, null);
	   convertView.setBackgroundResource(R.color.hosptial_name);
	   holder.province = (TextView) convertView.findViewById(R.id.province);
	   holder.province.setText(list.get(position));
	   
	   convertView.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			profession.setprofession().setText(list.get(i));
			
			PopupWindow popupWindow = profession.dismisspoppwindow();
			if (popupWindow != null && popupWindow.isShowing()) {
				popupWindow.dismiss();
				Constant.flag_vocation = true;
			}
			String  conts=list.get(i).toString();
			if("医师".equals(conts))
			 Constant.PROFESSION="住院医师";
			else
				Constant.PROFESSION=conts;
			if("不限".equals(Constant.PROFESSION))
				Constant.PROFESSION="";
			 Intent it = new Intent(BroadcastAction.ACTION_SEND_EXPERT_LIST_REQUESTION);  
             context.sendBroadcast(it); 
		}
	});
	return convertView;
}
   
   public void   setprofession(SetProfession profession){
	   this.profession=profession;
   }
   
   public interface SetProfession{
	   public TextView  setprofession();
	   public PopupWindow  dismisspoppwindow();
	   
	   
   }
   
   
   
   
   private class viewholder{
	   TextView province;
   }
}
